package io.renren.modules.noc.service.impl;

import io.renren.modules.noc.entity.NocWenjuanEntity;
import io.renren.modules.noc.service.NocWenjuanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import io.renren.modules.noc.dao.NocWenjuanOptionDao;
import io.renren.modules.noc.entity.NocWenjuanOptionEntity;
import io.renren.modules.noc.service.NocWenjuanOptionService;


@Service("nocWenjuanOptionService")
public class NocWenjuanOptionServiceImpl extends ServiceImpl<NocWenjuanOptionDao, NocWenjuanOptionEntity> implements NocWenjuanOptionService {

    @Autowired
    private NocWenjuanService nocWenjuanService;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<NocWenjuanOptionEntity> page = this.page(
                new Query<NocWenjuanOptionEntity>().getPage(params),
                new QueryWrapper<NocWenjuanOptionEntity>()
        );

        for(NocWenjuanOptionEntity nocWenjuanOptionEntity : page.getRecords()){
            NocWenjuanEntity nocWenjuanEntity = nocWenjuanService.getById(nocWenjuanOptionEntity.getWenjuanId());
            if(nocWenjuanEntity != null){
                nocWenjuanOptionEntity.setWenjuanName(nocWenjuanEntity.getTitle());
            }
        }

        return new PageUtils(page);
    }

}
